/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package org.sbbs.demo.manager.impl;

import jakarta.annotation.PostConstruct;
import java.util.concurrent.CompletableFuture;
import lombok.extern.slf4j.Slf4j;
import org.sbbs.base.cache.manager.impl.BaseManagerCacheImpl;
import org.sbbs.demo.dao.DemoBeanRepository;
import org.sbbs.demo.entity.DemoBean;
import org.sbbs.demo.manager.DemoBeanManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 *
 * @author jenkins
 */
@Service
@Qualifier("demoBeanCacheManager")
@Slf4j
public class DemoBeanCacheManagerImpl extends BaseManagerCacheImpl<DemoBean, Long, DemoBeanRepository> implements DemoBeanManager {

    @Autowired
    private DemoBeanRepository demoBeanRepository;

    @PostConstruct
    public void init() {
        super.setRepo(demoBeanRepository);
        this.setCache(this.getCacheManager().getCache("DemoBeanCache"));
        this.getCache().clear();

        CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
            this.load(true);
        });
    }
//
//    @Override
//    public Page<DemoBean> findAll(Pageable pageable) {
//        StopWatch sw = new StopWatch();
//        sw.start();
//
//        List<DemoBean> l = new ArrayList<>();
//        Page<?> p = this.demoBeanRepository.findAllIds(pageable);
//        List<?> ids = p.getContent();
//        for (Object id : ids) {
//            Cache.ValueWrapper t = this.getCache().get(id);
//            if (t != null) {
//                l.add((DemoBean) t.get());
//            } else {
//                DemoBean b = (DemoBean) super.findById((Long) id);
//                this.getCache().put(id, b);
//                log.debug("更新缓存:{}key{}", this.getCache().getName(), b.getId());
//            }
//        }
//        ids = l;
//        sw.stop();
//        log.debug("findAllPage耗时:" + sw.getTotalTimeMillis());
//
//        return (Page<DemoBean>) p; 
//    }

}
